package com.itheima.comment.controller;
import com.itheima.comment.docs.CommentVo;
import com.itheima.comment.dto.CommentDto;
import com.itheima.comment.dto.CommentLikeDto;
import com.itheima.comment.dto.CommentSaveDto;
import com.itheima.comment.pojo.ApComment;
import com.itheima.comment.service.ApCommentService;
import com.itheima.common.pojo.PageInfo;
import com.itheima.common.pojo.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.itheima.core.controller.AbstractCoreController;

/**
* <p>
* APP评论信息表 控制器</p>
* @author 作者
* @since 2021-09-01
*/
@RestController
@RequestMapping("/apComment")
@CrossOrigin
public class ApCommentController extends AbstractCoreController<ApComment> {

    private ApCommentService apCommentService;

    //注入
    @Autowired
    public ApCommentController(ApCommentService apCommentService) {
        super(apCommentService);
        this.apCommentService=apCommentService;
    }

    /***
     * 文章评论列表
     */
    @PostMapping(value = "/loadPage")
    public Result loadPage(@RequestBody CommentDto dto){
        PageInfo<CommentVo> comments = apCommentService.loadPage(dto);
        return Result.ok(comments);
    }


    /***
     * 评论保存
     */
    @PostMapping(value = "/saveToMongo")
    public Result saveToMongo(@RequestBody CommentSaveDto dto){
        apCommentService.saveToMongo(dto);
        return Result.ok();
    }


    /***
     * 点赞/取消点赞
     */
    @PostMapping(value = "/liks")
    public Result likes(@RequestBody CommentLikeDto dto){
        apCommentService.likes(dto);
        return Result.ok();
    }
}

